package MethodDemo;

public class test3 {
    public static void main(String[] args) {
        //将一个数组从from到to的索引copy到new数组中
        int[] arr={1,2,3,4,5,6,7,8,9};
        int[] newarr=copyArr(arr,3,7);
        //输出
        for (int i = 0; i < newarr.length; i++) {
            System.out.print(newarr[i]+" ");
        }
    }

    public static int[] copyArr(int[] arr,int form,int to){
        //计算有多少个数要copy
        int[] Newarr=new int[to-form];
        //新数组的下标
        int Index=0;
        //复制
        for (int i = form; i < to; i++) {
            Newarr[Index]=arr[i];
            Index++;
        }
        return Newarr;
    }
}
